<?php

namespace Admin\Controller;
use Think\Controller;

    class DiaryController extends Controller{

        function showlist(){
            $article=new \Model\DiaryModel();
            $article_info=$article->order('id desc')->select();
            $this->assign('article_info',$article_info);
            $this->display();
        }
        function add(){

            $article=new \Model\DiaryModel();
            if(!empty(I('POST.content'))){
                $info=$_POST;
                dump($info);
                $return=$article->add($info);
                if($return){
                    $this->redirect('showlist',array(),'0',"添加成功");
                }else{
                    $this->redirect('add',array(),'2','添加失败');
                }
            }
            $this->display();
        }

        function shanchu($id){
            $article=M('Diary');
            $return=$article->delete($id);
            if($return){
                $this->redirect('showlist',array(),'0','删除成功');
            }else{
                $this->redirect('showlist',array(),'2','删除失败');
            }
            $this->display();
        }
        function update($id){
            $article=M('Diary');
            if(!empty(I('POST.content'))){
                $return=$article->where("id=$id")->save($_POST);
                if($return){
                    $this->redirect('showlist',array(),'1','<h2>修改成功</h2>');
                }else{
                    $this->redirect('update',array('id'=>$id),'5','<h2>修改失败</h2>');
                }
            }
            $info=$article->find($id);
            $this->assign('info',$info);
            $this->display();
        }
    }

?>